Python编程快速上手 | 您所在的位置:网站首页 › python编程快速上手 让繁琐工作自动化 第2版 › Python编程快速上手 |
mac版代码,windows未知 10.8.1 选择性复制 import os, shutil from pathlib import Path p = Path('原始文件位置') tarp = '目标文件位置' for foldername, subfolders, filenames in os.walk(p): print('Running os.walk step......') print('The current folder is ' + foldername) for tarFile in p.glob('*.pdf'): shutil.move(tarFile, tarp) for tarFile in p.glob('*.txt'): shutil.move(tarFile, tarp) for subfolder in subfolders: print('The current folder is ' + foldername + ':' + subfolder) psubFolder = os.path.join(p, subfolder) for tarFile in Path(psubFolder).glob('*.pdf'): shutil.move(tarFile, tarp) for tarFile in Path(psubFolder).glob('*.txt'): shutil.move(tarFile, tarp) |
CopyRight 2018-2019 实验室设备网 版权所有 |